#include <jni.h>
#include <string>
#include "leetcode/Find132pattern.cpp"
#include "leetcode/DeleteDuplicates.cpp"

extern "C" JNIEXPORT jstring JNICALL

Java_com_linanqing_jnijavademo_JavaJni_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}


extern "C"
JNIEXPORT jboolean JNICALL
Java_com_linanqing_jnijavademo_JavaJni_find132pattern(JNIEnv *env, jobject thiz, jintArray arrays) {
    // TODO: implement find132pattern()
    Find132pattern solution;
    jboolean isCp = JNI_FALSE;
    jint *array = env->GetIntArrayElements(arrays, &isCp);
    int length = env->GetArrayLength(arrays);
    vector<int> vc(array, array + length);
    return solution.find132pattern(vc);
}

extern "C"
JNIEXPORT jintArray JNICALL
Java_com_linanqing_jnijavademo_JavaJni_deleteDuplicates(JNIEnv *env, jobject thiz,
                                                        jintArray arrays) {
    // TODO: implement deleteDuplicates()
    DeleteDuplicates deleteDuplicates;
    jboolean isCp = JNI_FALSE;

    //Desc:-  1.拿到数组
    jint *array = env->GetIntArrayElements(arrays, &isCp);
    int length = env->GetArrayLength(arrays);

    //Desc:-  2.将数组专程链表 并 进行处理
    ListNode *listNode = deleteDuplicates.deleteDuplicates(
            deleteDuplicates.createLinkList(array, length));

    //Desc:-  3.将得到的链表数据转成数组，并进行返回

    int a[length];
    int i = 0;
    while (listNode->next) {
        a[i] = listNode->val;
        i++;
    }
    jintArray jintArray1 = env->NewIntArray(length);

}